<?
class Reviews extends Controller
{
	const DEFAULT_CATEGORY = 'console';

	public function __construct()
	{
		parent::Controller();		
	}
	
	/*
	*	editReview()
	*	@PARA: null
	*	@RETURN: null
	*/
	public function editReview($gameID)
	{
		$this->load->helper('url');
		//$gameID = $this->input->post('gameID');
		$submit = $this->input->post('submit');
		if($submit)
		{
			$data = $this->_getFormValues();
			$this->load->model('reviews_model', 'reviewsModel');
			$newID = $this->reviewsModel->add($data);
			redirect('/reviews/editReview/'.$data['game_id'], 'location');			
		}
		else
		{//show edit form
			//get menu
			$data['menuView'] = $this->_getMenuView();	

			$this->load->model('reviews_model', 'reviewsModel');
			//review listing
			$listReviewData['reviewsList'] = $this->reviewsModel->getGameReviews($gameID);
			$data['productionView'] = $this->load->view('reviews/list_reviews', $listReviewData, true);	
			//review edit form
			$editReviewData['gameID'] = $gameID;			
			$editReviewData['reviewDetails'] = $this->reviewsModel->getLatestReview($gameID);
			$data['productionView'] .= $this->load->view('reviews/edit_review', $editReviewData, true);					
		}
		
		$this->load->library('layout');			
		$this->layout->render_page('homepage/main_page', $data);
	}
	
	/*
	*	getFormValues
	*	@PARA: null
	*	@RETURN: $data
	*	@ACCESS: private
	*/
	private function _getFormValues()
	{
		$data['id']			= '';
		$data['review_content']	= $this->input->post('review_content', TRUE);
		$data['game_id']	= $this->input->post('game_id', TRUE);		
		$data['user_id']	= $this->input->post('user_id', TRUE);

		return $data;
	}	
	
	/*
	*	getMenuView - this is duplcated in games. Have to think about how to resolve that.
	*	@PARA: catgory
	*	@RETURN: $menuView
	*	@ACCESS: private
	*/
	private function _getMenuView($category=null)
	{
		$menuView= '';
		$this->load->model('menus_model', 'menusModel');
		$menuData = $this->menusModel->getMenuData();
		if($menuData)
		{
			$menuView = $this->load->view('homepage/category_menus', $menuData, true);
		}
		return $menuView;
	}
}
?>